{template 'common/header'}
	<div class="panel we7-panel ng-scope" >
	<div class="panel-heading">编辑优惠券</div>
	<div class="panel-body we7-padding">
		<div class="form-horizontal">
			<div class="form-group">
				<label class="col-sm-2 control-label">优惠券标题</label>
				<div class="col-sm-8">
					<input type="text" class="form-control" id="title" name="title" value="{$card['title']}">
				</div>
		 	</div>	 		
			<div class="form-group">
				<label class="col-sm-2 control-label">使用条件</label>
				<div class="col-sm-8">
					<input type="number" class="form-control" id="condition" name="condition" value="{$card['condition']}">
					<span class="help-block">&nbsp;&nbsp;消费满多少元可减</span>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">卡券颜色</label>
				<div class="col-sm-8">
					{php echo tpl_form_field_color('bg_color', $card['bg_color']);}
				</div>
		 	</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">时间限制</label>
				<div class="col-sm-4">
					{php echo _tpl_form_field_date(starttime, $card['starttime']);}
					<span class="help-block">&nbsp;&nbsp;使用时段</span>
				</div>
				<div class="col-sm-4">
					{php echo _tpl_form_field_date(endtime, $card['endtime']);}
				</div>				
		 	</div>

			<div class="form-group">
				<label class="col-sm-2 control-label">优惠方式</label>
					<div class="col-sm-8">
						<label class="radio radio-inline">
							<input type="radio" name='card_type' id="card_type_gen" value="GENERAL_COUPON" {if $card['card_type']=='GENERAL_COUPON'}checked="checked"{else}{/if}> 立减
						</label>
						<label class="radio radio-inline">
							<input type="radio" name='card_type' id="card_type_dis" value="DISCOUNT" {if $card['card_type']=='DISCOUNT'}checked="checked"{else}{/if}> 打折
						</label>					
					</div>
		 	</div>		


			<div class="form-group hide" id="GBOX">
				<label class="col-sm-2 control-label"></label>
				<div class="col-sm-8">
				    <div class="input-group">
				      <div class="input-group-addon">立减</div>
				      <input type="number" class="form-control" id="minus" placeholder="" value="{$card['minus']}">
				      <div class="input-group-addon">元</div>
				    </div>			
				</div>
		 	</div>

			<div class="form-group hide" id="DBOX">
				<label class="col-sm-2 control-label"></label>
				<div class="col-sm-8">
				    <div class="input-group">
				      <div class="input-group-addon">打</div>
				      <input type="number" class="form-control" id="discount" placeholder="1-9.9之间" value="{$card['discount']}">
				      <div class="input-group-addon">折</div>
				    </div>			
				</div>
		 	</div>	

			<div class="form-group">
				<label class="col-sm-2 control-label">发放总数</label>
				<div class="col-sm-8">
					<input type="number" class="form-control" id="total_quantity" name="total_quantity" value="{$card['total_quantity']}">
					<span class="help-block">&nbsp;&nbsp;优惠券总数量，没有不能领取或发放</span>
				</div>
		 	</div>

			<div class="form-group">
				<label class="col-sm-2 control-label">领取限制</label>
				<div class="col-sm-8">
				    <div class="input-group">
				      <div class="input-group-addon">每人限领</div>
				      <input type="text" class="form-control" id="get_limit" placeholder="" value="{$card['get_limit']}">
				      <div class="input-group-addon">张</div>				      
				    </div>
				    <span class="help-block">&nbsp;&nbsp;每人能领取几张，0则不能领取</span>	
				</div>
		 	</div>

			<div class="form-group">
				<label class="col-sm-2 control-label">排序</label>
				<div class="col-sm-8">
					<input type="number" class="form-control" id="orderid" name="orderid" value="{$card['orderid']}">
					<span class="help-block">&nbsp;&nbsp;数值越大越靠前</span>
				</div>
		 	</div>		 			 	
			<div class="form-group">
				<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">是否上架</label>
				<div class="col-xs-12 col-sm-8">
					<label class="radio radio-inline">
						<input type="radio" name="status" id="status" value="0" {if intval($card['status']) != 1}checked="checked"{/if}> 下架
					</label>
					<label class="radio radio-inline">
						<input type="radio" name="status" id="status" value="1" {if intval($card['status']) == 1}checked="checked"{/if}> 上架
					</label>
				</div>
			</div>	
			<button type="button" id="save_" class="btn btn-info" style="display: block; margin-left: auto;margin-right: auto;">提交保存</button>
		</div>
	</div>	
</div>
<style type="text/css">.right-content{padding: 0;} .hide{display: none;}</style>
<link rel="stylesheet" href="{MODULE_URL}public/css/Toast.css">
<script src="{MODULE_URL}public/js/Toast.js"></script>
<script type="text/javascript">
	window.onload = function(){
		var card_type = $.trim($("input[name='card_type']:checked").val());
		if(card_type=='DISCOUNT'){
			$('#DBOX').removeClass('hide');
		}else if(card_type=='GENERAL_COUPON'){
			$('#GBOX').removeClass('hide');
		}

	}
	$("#card_type_gen").on("click",function(){
			$('#GBOX').removeClass('hide');
			if(!$("#DBOX").hasClass("hide")){
				$('#DBOX').addClass('hide')
			}	
	})	
	$("#card_type_dis").on("click",function(){
			$('#DBOX').removeClass('hide');
			if(!$("#GBOX").hasClass("hide")){
				$('#GBOX').addClass('hide')
			}	
	})

	$('#save_').on('click',function(){
		$('#save_').addClass('disabled');
		var id = '{$cid}';
		var title = $.trim($('#title').val());
		var condition = $.trim($('#condition').val());
		var starttime = $.trim($('input[name="starttime"]').val());
		var endtime = $.trim($('input[name="endtime"]').val());
		var card_type = $.trim($("input[name='card_type']:checked").val());
		var bg_color = $.trim($('input[name="bg_color"]').val());
		var minus  = $.trim($('#minus').val());
		var discount = $.trim($('#discount').val());
		var total_quantity = $.trim($('#total_quantity').val());
		var get_limit = $.trim($('#get_limit').val());
		var orderid = $.trim($('#orderid').val());
		var status = $.trim($("input[name='status']:checked").val());
		if(title == ''){
			mqToast({type:1,context:'请填写卡券标题'});
			return false;			
		}
		if(condition==''){
			mqToast({type:1,context:'请填写使用条件'});
			return false;	
		}
		if(starttime=='' || endtime == ''){
			mqToast({type:1,context:'请选择时间限制'});
			return false;	
		}
		if(card_type==''){
			mqToast({type:1,context:'请选择优惠方式'});
			return false;			
		}
		if(card_type=='GENERAL_COUPON' && minus==''){
			mqToast({type:1,context:'请填写减免金额'});
			return false;			
		}
		if(card_type=='DISCOUNT' && discount==''){
			mqToast({type:1,context:'请填写折扣'});
			return false;			
		}
		if(total_quantity==''){
			mqToast({type:1,context:'请填写发放优惠券总额'});
			return false;	
		}
		if(get_limit==''){
			mqToast({type:1,context:'请填写每人领取多少张'});
			return false;			
		}						
		$.ajax({
			url:"{php echo $this->createWebUrl('save_cardedit');}&version_id="+"{$_GPC['version_id']}",
			data:{id:id,title:title,condition:condition,starttime:starttime,endtime:endtime,card_type:card_type,bg_color:bg_color,minus:minus,discount:discount,total_quantity:total_quantity,get_limit:get_limit,orderid:orderid,status:status},
			dataType:"json",
			type:"post",	
			success:function(res){
				if(res.status==1){
					mqToast({type:1,context:res.msg});
					  setTimeout(function(){
		                window.location.reload();
		              },2000);					
					return false;
				}else{
					mqToast({type:2,context:res.msg});
					$('#save_').removeClass('disabled');
					return false;

				}
			}					
		})

	})

	


</script>
{template 'common/footer'}